package org.demon.springtest.design.proxy;

import org.springframework.cglib.proxy.Enhancer;

public class QueryMain {

    public static void main(String[] args) {
        JdkQueryProxy handler = new JdkQueryProxy();

        IQuery proxy = (IQuery) handler.getJDKProxy(new QueryImpl());
        System.out.println(proxy.hello());


        CglibQueryProxy hacker = new CglibQueryProxy();

        //cglib 中 用来创建动态代理
        Enhancer enhancer = new Enhancer();
        //设置要创建动态代理的类
        enhancer.setSuperclass(QueryImpl.class);
        // 设置回调，对于代理类上所有方法的调用，都会调用CallBack，而Callback则需要实行intercept()方法进行拦截
        enhancer.setCallback(hacker);
        QueryImpl p = (QueryImpl) enhancer.create();
        p.request();

        IQuery query = new QueryImpl();
        query.world();
    }
}
